import os
import sys
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
from Widgets.palette_color import showColor

class ProjectInfoWindow(QWidget):
    ip_Singnal=Signal(str)
    def __init__(self,project_info_path):
        super(ProjectInfoWindow, self).__init__()
        #全局变量
        self.project_info_path=project_info_path

        self.setWindowTitle('设置项目信息路径')
        self.setPalette(showColor('bg'))
        self.main_layout=QVBoxLayout()
        self.ip_layout=QHBoxLayout()
        self.ip_layout.setSpacing(15)
        self.ip_label=QLabel('项目信息路径:')
        self.ip_label.setPalette(showColor('font'))
        self.ip_edit=QLineEdit()
        self.ip_edit.setText(self.project_info_path)
        self.path_btn=QPushButton('...')
        self.path_btn.clicked.connect(self._project_dir)
        self.path_btn.setMaximumWidth(50)
        self.ip_btn=QPushButton('OK')
        self.ip_btn.setMaximumWidth(50)
        self.ip_btn.clicked.connect(self.ip_confirm)
        self.ip_layout.addWidget(self.ip_label)
        self.ip_layout.addWidget(self.ip_edit)
        self.ip_layout.addWidget(self.path_btn)
        self.ip_layout.addWidget(self.ip_btn)



        self.port_layout=QHBoxLayout()
        self.port_label=QLabel('port:')
        self.port_edit=QLineEdit()
        self.port_layout.addWidget(self.port_label)
        self.port_layout.addWidget(self.port_edit)


        self.main_layout.addLayout(self.ip_layout)
        self.setLayout(self.main_layout)

    def _project_dir(self):
        dir=QFileDialog.getExistingDirectory(self,'选择文件夹')
        self.ip_edit.setText(dir)
        print(dir)

    def ip_confirm(self):
        ip_path=self.ip_edit.text()
        print('ip_path:',ip_path)
        self.ip_Singnal.emit(ip_path)
        self.close()

if __name__ == '__main__':
    app=QApplication(sys.argv)
    p=ProjectInfoWindow()
    p.show()
    sys.exit(app.exec_())